$(document).ready(function() {		
	$("#frmComment").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {				
			pcontent: {
				requiredContent		: true,
				minlengthContent	: true
			}
		},
		messages: {	
			pcontent: {
				requiredContent		: content_required,
				minlengthContent	: content_minlength
			}
		},
		errorPlacement: function(label, element) {	
			var id = element.attr('id');	
			label.insertAfter($('#' + id));			
		},
		submitHandler: function(form) {	
			$('#formCmt').hide();
			$('#loading').show();
			var strContent	= encodeURIComponent($('#pcontent').val());	
			var intBlogId 	= $('#pblogid').val();
			$.getJSON(				
				HOST_VFRIEND + 'comment/bcmtsend?content='+strContent+'&blogid='+intBlogId+'&callback=?',		
				function(response) {					
					if(response['error'] == 0) {						
						showUIMessage(response['msg']);
						$('#sComment').html(response['data']);						
						$('#sTotal').html(response['total']);
					} else {
						alert(response['msg']);
					}
					$('#loading').hide();
					$('#formCmt').show();
					$('#pcontent').val('');
				}
			);
		}
	});
	$.validator.addMethod('requiredContent',function(){
		var strContent	= stripTags($('#pcontent').val());		
		if(strContent == '' || strContent.toLowerCase() == 'viết bình luận')
			return false;		
		return true;												 
	});
	$.validator.addMethod('minlengthContent',function(){
		var strContent	= stripTags($('#pcontent').val());			
		if(strContent != '' && strContent.toLowerCase() != 'viết bình luận' && strContent.length < 2)
			return false;		
		return true;												 
	});
});
function likeBlog(intBlogId) {
	$.getJSON(				
		HOST_VFRIEND + 'ajax/blog?act=1&blogid='+intBlogId+'&callback=?',		
		function(response) {					
			if(response['error'] == 0) {						
				showUIMessage(response['msg']);
				$('#bd' + intBlogId).html(response['like']);
			} else {
				alert(response['msg']);
			}
		}
	);
}
function deleteBlog(intVal, strLink) {
	if(confirm(confirm_blog_delete) == true) {		
		$.getJSON(				
		HOST_VFRIEND + 'ajax/blog?act=2&blogid='+intVal+'&callback=?',		
			function(response) {					
				if(response['error'] == 0) {						
					showUIMessage(response['msg']);
					setTimeout(function(){
						document.location.href = strLink;	
					},1000);
									
				} else {
					alert(response['msg']);
				}
			}
		);
	} 
}
function deleteCmt(intVal,intPage) {	
	if(confirm(confirm_delete) == true) {
		var intBlogId 	= $('#pblogid').val();
		$.getJSON(				
			HOST_VFRIEND + 'comment/bcmtsend?act=1&blogid='+intBlogId+'&bcommentid='+intVal+'&page='+intPage+'&callback=?',		
			function(response) {					
				if(response['error'] == 0) {						
					showUIMessage(response['msg']);
					$('#sComment').html(response['data']);
					$('#sTotal').html(response['total']);
				} else {
					alert(response['msg']);
				}
			}
		);
	} 
}
function likeCmt(intVal,intPage) {	
	var intBlogId 	= $('#pblogid').val();
	$.getJSON(				
		HOST_VFRIEND + 'comment/bcmtsend?act=2&blogid='+intBlogId+'&bcommentid='+intVal+'&page='+intPage+'&callback=?',		
		function(response) {					
			if(response['error'] == 0) {						
				showUIMessage(response['msg']);
				$('#sComment').html(response['data']);
				$('#lcmt' + intVal).html(response['like']);
			} else {
				alert(response['msg']);
			}
		}
	);
}

onMouseOverForCmt = function(intId) {
	$('#rowCmt' + intId).show();
}
onMouseOutForCmt = function(intId) {
	$('#rowCmt' + intId).hide();
}